package com.atguigu.crud.service;

import com.atguigu.crud.bean.Wallet;
import com.atguigu.crud.bean.WalletExample;
import com.atguigu.crud.dao.WalletMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service("walletService")
public class WalletService {
	@Autowired
	private WalletMapper walletMapper;


    //条件查询交易记录
	public Map<String,Object> getAllByPars(Wallet rec) {
		Map<String,Object> m=new HashMap<String, Object>();
		List<Wallet> gr=walletMapper.selectByExampleBygroupby();// 所有币种
        //封装成map 对象
		for (int i=0;i<gr.size();i++){
            m.put(gr.get(i).getIcconname(),getGroup(gr.get(i).getIcconname()));
		}
		 return m;
	}

	// 分组查询查询
	public List<Wallet> getGroup(String iconname) {
		WalletExample r = new WalletExample();
		WalletExample.Criteria c=r.createCriteria();
		c.andIcconnameEqualTo(iconname);
		r.setOrderByClause("crtime desc");
		return walletMapper.selectByExample(r);
	}
// id 查询对象
	public Wallet getRecord(String id) {
		System.out.println("参数id为："+id);
		return walletMapper.selectByPrimaryKey(id);
	}

	//通过  eth  查询 list 条件
	public List<Wallet> getRecordbyPars(Wallet wallet){
		WalletExample r = new WalletExample();
		WalletExample.Criteria c=r.createCriteria();
		c.andIcconnameEqualTo(wallet.getIcconname());
		r.setOrderByClause("crtime desc");
	  return walletMapper.selectByExample(r);
	}
   // 保存
	public void saveRec(Wallet wallet) {
		wallet.setId(UUID.randomUUID().toString());
		wallet.setCrtime(new Date());
		wallet.setName(wallet.getName());
		wallet.setAddress(UUID.randomUUID().toString());
		wallet.setIcconname(wallet.getIcconname());
		walletMapper.insertSelective(wallet);
	}
//通过id删除
	public void delByid(String id) {
		walletMapper.deleteByPrimaryKey(id);
	}
//更新信息
	public void updateRec(Wallet wallet) {
		walletMapper.updateByPrimaryKeySelective(wallet);
	}
}
